<template>
  <div class="app-container">
    <el-tabs v-model="listQuery.status" type="card" style="margin-bottom:10px">
      <el-tab-pane v-for="item in jcRegStatusJson" :key="item.value" :label="item.label" :name="item.value+''">
      </el-tab-pane>
    </el-tabs>
    <div class="filter-container">
      <el-input v-model="listQuery.matchIdentifier" placeholder="挂牌编号" class="filter-item" clearable/>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"
        >
        查询
      </el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row row-key="id" style="width: 100%;">
      <el-table-column label="序号" type="index" align="center" width="60px" />
      <el-table-column label="挂牌编号" prop="matchIdentifier" align="center" />
      <el-table-column label="产品名称" prop="name" align="center" />
      <el-table-column label="分类名称" prop="categoryName" align="center" />
      <el-table-column label="单位" prop="unit" align="center" />
      <el-table-column label="本次报价" prop="price" align="center" />
      <el-table-column label="期望价格（单价）" prop="topPrice" align="center" />
      <el-table-column label="期望数量" prop="topNum" align="center" />
      <el-table-column label="创建时间" prop="createTime" align="center" width="160px" />
      <el-table-column label="状态" prop="statusText" align="center" >
        <template slot-scope="{row}">
          <el-tag :type="row.status | statusFilter">
            {{ row.statusText }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { matchDetailPageByQo } from '@/api/transaction'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { jcRegStatusJson } from '../constant'

export default {
  name: 'TransactionGroupBuying',
  directives: { waves },
  components: { Pagination },
  filters: {
    statusFilter(status) { //状态
      const statusMap = {
        2: '',
        3: 'success',
        99: 'danger',
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        status: '2',
        pageNo: 1,
        pageSize: 20,
        matchIdentifier: '',
      },
      jcRegStatusJson,
      dialogDetailVisible: false,
      detail: {}
    }
  },
  watch: {
    'listQuery.status': function () {
      this.handleFilter()
    },
  },
  created() {
    if (this.$route.query.status && this.listQuery.status !== this.$route.query.status.toString()) {
      this.listQuery.status = this.$route.query.status.toString()
    }
    if (this.$route.query.identifier) {
      this.listQuery.matchIdentifier = this.$route.query.identifier.toString();
    }

    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      matchDetailPageByQo(this.listQuery).then(response => {
        this.list = response.list || []
        this.total = response.totalCount
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.getList()
    },
  }
}
</script>

<style lang="scss" scoped>
.el-row {
  line-height: 2;
  font-size: 15px;
}
</style>